package com.ellison.springdemo.springbase.mvc;

import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.validation.MessageCodesResolver;
import org.springframework.validation.Validator;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.*;

import java.util.List;

/**
 * <p>MVC 自定义配置
 *
 * @author Ellison_Pei
 * @date 2022/3/9 18:59
 * @since 1.0
 **/
@Configuration
public class MvcCustomConfigurer implements WebMvcConfigurer {
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> configurePathMatch=========");
        WebMvcConfigurer.super.configurePathMatch(configurer);
    }

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> configureContentNegotiation=========");
        WebMvcConfigurer.super.configureContentNegotiation(configurer);
    }

    @Override
    public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> configureAsyncSupport=========");
        WebMvcConfigurer.super.configureAsyncSupport(configurer);
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> configureDefaultServletHandling=========");
        WebMvcConfigurer.super.configureDefaultServletHandling(configurer);
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> addFormatters=========");
        WebMvcConfigurer.super.addFormatters(registry);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> addInterceptors=========");
        UserInterceptor userInterceptor = new UserInterceptor();
        registry.addInterceptor(userInterceptor);
        System.out.println("=========添加自定义 userInterceptor =========");
        WebMvcConfigurer.super.addInterceptors(registry);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> addResourceHandlers=========");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> addCorsMappings=========");
        WebMvcConfigurer.super.addCorsMappings(registry);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> addViewControllers=========");
        WebMvcConfigurer.super.addViewControllers(registry);
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> configureViewResolvers=========");
        WebMvcConfigurer.super.configureViewResolvers(registry);
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> addArgumentResolvers=========");
        WebMvcConfigurer.super.addArgumentResolvers(resolvers);
    }

    @Override
    public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> handlers) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> addReturnValueHandlers=========");
        WebMvcConfigurer.super.addReturnValueHandlers(handlers);
    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> configureMessageConverters =========");
        WebMvcConfigurer.super.configureMessageConverters(converters);
    }

    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> extendMessageConverters=========");
        WebMvcConfigurer.super.extendMessageConverters(converters);
    }

    @Override
    public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> configureHandlerExceptionResolvers=========");
        WebMvcConfigurer.super.configureHandlerExceptionResolvers(resolvers);
    }

    @Override
    public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> extendHandlerExceptionResolvers=========");
        WebMvcConfigurer.super.extendHandlerExceptionResolvers(resolvers);
    }

    @Override
    public Validator getValidator() {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> getValidator=========");
        return WebMvcConfigurer.super.getValidator();
    }

    @Override
    public MessageCodesResolver getMessageCodesResolver() {
        System.out.println("调用到自定义MVC配置类：=========MvcCustomConfigurer -> getMessageCodesResolver=========");
        return WebMvcConfigurer.super.getMessageCodesResolver();
    }
}
